var globalData = {};
var turn = function(){
    alert("正在加载。。");
}
var object = {};
var arrobject = [];
$(function () {
    layer.load();
    $('body').show();
    globalData.flowId = $.getQueryString("flowId");
    globalData.flowStep = $.getQueryString("flowStep") || '';
    globalData.prcsId = $.getQueryString("prcsId") || '';
    globalData.runId = $.getQueryString("runId") || '';
    globalData.tableName = $.getQueryString("tableName") || '';
    globalData.tabId =  $.getQueryString("tabId") || '';
    //alert(globalData.runId);
    var workformh5 = {
        init:function (cb) {
            var _this = this;

            workForm.init({
                    formhtmlurl:'../../workflow/work/workfastAdd',//URL
                    resdata:{
                        flowId:globalData.flowId,
                        runId:globalData.runId,
                        prcsId:globalData.prcsId,
                        flowStep:globalData.flowStep
                    },
                    flowStep:globalData.flowStep,//预览
                    target:'.cont_form',
                    preView:true,
                    ish5:true
                },
                function (data,option,target) {

                    globalData.flowRun = data.object.flowRun;
                    globalData.listFp = data.object.listFp;
                    globalData.flowRunPrcs = data.object.flowRunPrcs;
                    globalData.option = option;
                    globalData.flowTypeModel = data.object.flowTypeModel;
                    globalData.attachPriv = data.object.attachPriv;
                    globalData.allowBack = data.object.allowBack;
                    globalData.flowPrcs = data.object.flowRunPrcs.flowPrcs;
                    globalData.signlock = data.object.signlock;
                    globalData.flowFormType = data.object.flowFormType;
                    globalData.feedback = data.object.feedback;
                    globalData.flowProcesses = data.object.flowProcesses;

                    /*********************交办详情按钮显示方法*************************/
                    $.get('/flowAssign/query', {runId: globalData.flowRun.runId}, function(res){
                        if (res.flag) {
                            $('#assignmentDetail').show();
                        }
                    });
                    
                    /*********************判断是否显示相关流程(父子流程和关联流程)*************************/
                    $.get('/workflow/work/prentAndSonFlow', {runId: globalData.flowRun.runId}, function (json) {
                        var parentRunId = '';
                        if (json.flag) {
                            var str2 = '';
                            if (json.object) {
                                parentRunId = json.object.runId;
                                str2 += '<tr><td>父流程</td><td><a flowid="' + json.object.flowId + '" runid="' + json.object.runId + '" href="javascript:;" style="color: blue;" class="open_flow_work">' + json.object.runName + '</a></td></tr>';
                            }
                            if (json.obj.length != 0) {
                                json.obj.forEach(function(item){
                                    str2 += '<tr><td>子流程</td><td><a flowid="' + item.flowId + '" runid="' + item.runId + '" href="javascript:;" style="color: blue;" class="open_flow_work">' + item.runName + '</a></td></tr>';
                                })
                            }
                            $('.connect_work_table').append(str2);
                            if (str2 != '') {
                                $('.connect_work').show();
                            }
                        }
                        // 获取关联流程数据
                        $.get('/flowRun/findrelationRunIds', {runId: globalData.flowRun.runId+','+parentRunId}, function (res) {
                            if (res.flag && res.obj.length > 0) {
                                var str = '';
                                res.obj.forEach(function (item) {
                                    str += '<tr><td>关联流程</td><td><a flowid="' + item.flowId + '" runid="' + item.runId + '" href="javascript:;" style="color: blue;" class="open_flow_work">' + item.runName + '</a></td></tr>';
                                });
                                $('.connect_work_table').append(str);
                                $('.connect_work').show();
                            }
                        });
                    });

                    if(globalData.signlock == 1){
                        $('.gapp_textarea').attr("disabled",true);
                    }
                    var runid = data.object.flowRun.runId;
                    if(globalData.allowBack != 0){
                        $('#backBtn').show();
                    }
                    $('#backBtn').click(function () {
                        if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
                            //alert(navigator.userAgent);
                            try{
                                window.webkit.messageHandlers.rightTitle.postMessage({'title':'转交','name':'审批及转交','function':'feedback'});
                            }catch(err){
                                rightTitle('转交','审批及转交','feedback');
                            }
                        } else if (/(Android)/i.test(navigator.userAgent)) {
                            //alert(navigator.userAgent);
                            Android.rightTitle('转交','xxxxx','feedback');
                        }
                        window.location.href='feedback?flowId='+globalData.flowId+'&flowStep='+globalData.flowStep+'&prcsId='+globalData.prcsId+'&runId='+globalData.flowRun.runId+'&allowback='+globalData.allowBack;
                    });
                    $.ajax({
                        type: "get",
                        url: "findworkUpload",
                        dataType: 'JSON',
                        data: {
                            runId:runid
                        },
                        success: function (obj) {
                            var data = obj.obj;
                            var img = '';
                            var names = '';
                            for(var i=0;i<obj.obj.length;i++){
                                var pic_name = obj.obj[i].attachName;
                                var index = pic_name .lastIndexOf("\.");
                                var pic_name = pic_name.substring(index + 1, pic_name .length);
                                var http = 'http://'+ window.location.host;
                                if(pic_name == "png"||pic_name == "jpeg"||pic_name == "bmp"||pic_name == "jpg"){
                                    img += '<img id="blah" src="/xs?'+ obj.obj[i].attUrl +'" onclick="anios($(this))" style="width:50px;height:50px;margin-right: 10px;margin-bottom: 10px;" url="'+ http + '/xs?'+ obj.obj[i].attUrl +'" name="'+ obj.obj[i].attachName +'">';
                                }else{
                                    if($.getQueryString("type") == 'EWC'){
                                        names += '<p><a style="margin-bottom: 5px;color: #095de0;" href="'+ http + '/download?'+ obj.obj[i].attUrl +'">'+ obj.obj[i].attachName +'</a></p>'
                                    }else {
                                        names += '<p url="'+ http + '/download?'+ obj.obj[i].attUrl +'" name="'+ obj.obj[i].attachName +'" onclick="anios($(this))">'+ obj.obj[i].attachName +'</p>'
                                    }
                                }
                            }
                            if(names == ''){
                                $('.uploadbox').hide();
                            }
                            $('.photo_box').append(img);
                            $('.uploadbox').append(names);
                        }
                    });

                    $.ajax({
                        type: "get",
                        url: "/flowProcess/getFlowFeedBack",
                        dataType: 'JSON',
                        data: {
                            runId:runid
                        },
                        success: function (obj) {
                            var str = '';
                            for(var i=0;i<obj.obj.length;i++){
                                if(obj.obj[i].feedFlag == 2){
                                    var feedflagstr = '<span style="font-size: 15px;font-weight: bold;color: red;">（回退意见）：</span>';
                                }else{
                                    var feedflagstr = '：';
                                }
                                str +=  '<div style="text-align: left;margin: 0px auto;margin-top: 15px;width: 90%;">' +
                                        '<span style="margin-bottom: 5px;font-size: 15px;font-weight: bold;">'+obj.obj[i].users.userName+feedflagstr+'</span>' +
                                        '<span style="font-size: 14px;padding: 0 5px;">'+obj.obj[i].content+'</span>' +
                                        '<span style="margin-bottom: 5px;font-size: 14px;">('+obj.obj[i].editTime+')</span>' +
                                        '</div>'
                            }
                            $('.hqbox').html(str);
                        }
                    });

                    $('#flowName').text(data.object.flowRun.runName);
                    $('#flowBeginUser').text(data.object.flowRun.userName);
                    $('#flowBeginTime').text(data.object.flowRun.beginTime);
                    $('#flowRunId').text('No.'+data.object.flowRun.runId);

                    // console.log(target)
                    _this.buildBody(target);
                    _this.buildEvent();
                    $('body').append('<script src="/js/workflow/plugin/countersignature/main.js"></script>');
                    cb();
                    //声明下评分控件START
                    if($('.mark').length != 0){
                        for(var i=0;i<$('.mark').length;i++){
                            var formItemId = $('.mark .form_item').eq(i).attr('name');
                            var value = $('.mark .form_item').eq(i).val();
                            scoreFun($("#startone"+formItemId));
                            if(value != '-1'){
                                $("#startone"+formItemId).find('a').eq(value).addClass('clibg');
                            }
                        }
                    }
                });

        },
        turnH5Btn:function(){
            var _this = this;
            _this.saveFlowData(function(res){
                if(res.flag){
                    var content = $('.signBox .gapp_textarea').val();
                    if(content != ''){
                        $.ajax({
                            type: "get",
                            url: "../../workflow/work/workfeedback",
                            dataType: 'JSON',
                            data: {
                                prcsId:globalData.prcsId,
                                runId:globalData.flowRun.runId,
                                flowPrcs:globalData.flowPrcs,
                                content:content,
                                file:''
                            },
                            success: function(res){
                            }
                        })
                    }
                    window.location.href='turnh5?flowId='+globalData.flowId+'&flowStep='+globalData.flowStep+'&prcsId='+globalData.prcsId+'&runId='+globalData.flowRun.runId;
                    if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
                        //alert(navigator.userAgent);
                        try{
                            window.webkit.messageHandlers.rightTitle.postMessage({'title':'转交','name':'123','function':'turn'});
                        }catch(err){
                            rightTitle('转交','123','turn');
                        }
                    } else if (/(Android)/i.test(navigator.userAgent)) {
                        //alert(navigator.userAgent);
                        Android.rightTitle('转交','123','turn');
                    }

                }

            });
        },
        buildEvent:function () {
            $.ajax({
                type: "get",
                url: "/form/getMobileDataSort",
                dataType: 'JSON',
                data: {
                    formId: globalData.flowFormType.formId
                },
                async:false,
                success: function(res) {
                    var formData = workForm.option.dataName || {};
                    if(res.flag){
                        var arr = res.obj.split(',');
                        var str = '';
                        var strArr = [];
                        var arrObj = {};
                        arr.forEach(function(v,i){
                            var name = v.split('|')[0] || '';
                            var isShow = v.split('|')[1] == 0 ? false : true;
                            arrObj[name] = isShow;
                            if(name&&name.indexOf('DATA_')>-1){
                                object[name] = true;
                                if($('[name='+ name +']').parents('tr').prop("outerHTML")){
                                   
                                    // 判断是否配置app显示
                                    if (!isShow) { // 未配置
                                        $('[name=' + name + ']').parents('tr').hide()
                                    } else { // 已配置
                                        var dataType = $('[name=' + name + ']').attr('data-type');
                                        // 判断内容是否为空，为空不显示
                                        if (!formData[name]) {
                                            $('[name=' + name + ']').parents('tr').hide()
                                        } else if (dataType == 'checkbox' && formData[name] == '0') {
                                            $('[name=' + name + ']').parents('tr').hide()
                                        }
                                    }
                                    
                                    // str += $('[name='+ name +']').parents('tr').prop("outerHTML");
                                    strArr.push($('[name='+ name +']').parents('tr'))
                                }
                            }
                        });
                        arrobject.forEach(function(v,i){
                            if(v&&v.indexOf('DATA_')>-1){
                                if(!object[v]){
                                    if($('[name='+ v +']').parents('tr').prop("outerHTML")){
                                        
                                        // 判断是否配置app显示
                                        if (!arrObj[v]) { // 未配置
                                            $('[name=' + v + ']').parents('tr').hide()
                                        } else { // 已配置
                                            var dataType = $('[name=' + v + ']').attr('data-type');
                                            // 判断内容是否为空，为空不显示
                                            if (!formData[v]) {
                                                $('[name=' + v + ']').parents('tr').hide()
                                            } else if (dataType == 'checkbox' && formData[v] == '0') {
                                                $('[name=' + v + ']').parents('tr').hide()
                                            }
                                        }
                                        
                                        // str += $('[name='+ v +']').parents('tr').prop("outerHTML");
                                        strArr.push($('[name='+ v +']').parents('tr'));
                                    }
                                }
                            }
                        });
                        $('#content tbody').empty();
                        $('#content tbody').html(strArr);
                    } else {
                        arrobject.forEach(function (v, i) {
                            if (v && v.indexOf('DATA_') > -1) {
                                if ($('[name=' + v + ']').parents('tr').prop("outerHTML")) {
                                    var dataType = $('[name=' + v + ']').attr('data-type');
                                    // 判断内容是否为空，为空不显示
                                    if (!formData[v]) {
                                        $('[name=' + v + ']').parents('tr').hide()
                                    } else if (dataType == 'checkbox' && formData[v] == '0') {
                                        $('[name=' + v + ']').parents('tr').hide()
                                    }
                                }
                            }
                        });
                    }
                }
            });
            var _this = this;
            $('#content').find('.qrcode').each(function () {
                var _this = $(this);
                var msg = {"mark":"SID_MEETING","url":_this.attr('textstr')};
                var id = _this.attr('id')
                var qrcode = new QRCode(id, {
                    text: JSON.stringify(msg),
                    width: _this.attr('orgwidth'),
                    height: _this.attr('orgheight'),
                    colorDark : '#000000',
                    colorLight : '#ffffff',
                    correctLevel : QRCode.CorrectLevel.H
                });
            });
            $('#lctbtn').click(function () {
                if($.getQueryString("type") == 'EWC'){
                    window.location.href = "/flowSetting/processDesignToolTwo?flowId="+ globalData.flowId +"&rilwId="+ globalData.runId;
                }else{
                    if(/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
                        try{
                            window.webkit.messageHandlers.lookFlowChart.postMessage({'url':"/flowSetting/processDesignToolTwo?flowId="+ globalData.flowId +"&rilwId="+ globalData.runId});
                        }catch(err){
                            lookFlowChart("/flowSetting/processDesignToolTwo?flowId="+ globalData.flowId +"&rilwId="+ globalData.runId);
                        }
                    }else if(/(Android)/i.test(navigator.userAgent)){
                        Android.lookFlowChart("/flowSetting/processDesignToolTwo?flowId="+ globalData.flowId +"&rilwId="+ globalData.runId);
                    }
                }

            });
            $('#turnBtn').click(function () {
                _this.turnH5Btn();
            });
            $('.btn_list').click(function () {
                var _this = $(this);
                layer.open({
                    type: 1,
                    title: "控件详情",
                    closeBtn: 1,
                    area: ['95%', '500px'],
                    content: _this.siblings('table'),
                    success:function (layero, index) {
                        layero.find('.table').css({
                            'color':'#555',
                            'margin-top':'20px'
                        }).find('td').css({
                            'border':'#dddddd 1pt solid',
                            'text-align': 'center'
                        });
                    },
                    end:function (layero,index) {
                        $('.tableplugin').hide();
                    }
                });
            });

            $('#saveBtn').click(function () {

                _this.saveFlowData(function(res){
                    if(res.flag){
                        alert("保存成功")
                    }else{
                        alert("保存失败")
                    }

                });
            });
            $('#deleteBtn').click(function () {
                alert('删除成功！');
            });
        },
        saveFlowData:function (cb) {
            var flowfun = globalData.flowRun;
            var form_item=$('#content .form_item');
            var realData=[];
            var radioArr = {};
            var modifydata =[];
            var flag = false;
            for(var i=0;i<form_item.length;i++){
                var baseData={};
                var value="";
                var obj = form_item.eq(i);
                var datatype = obj.attr("data-type");
                var key=obj.attr("name");
                var ismust = obj.attr('ismust');
                if(datatype=="select"){
                    value= obj.val()==0?'':form_item.eq(i).val();
                }else if(datatype=="textarea" || datatype=="text"  ){
                    value=obj.val();
                }else if(datatype=="checkbox"){
                    value=obj.attr('title');
                }else if(datatype=="macros"){
                    if(obj.attr('type') == "text"){
                        if(obj.attr('datafld')=='SYS_USERNAME'&&obj.attr('orgsignImg')==1){
                            if(obj.attr('signSrc')!=undefined&&obj.attr('signSrc')!=''){
                                value = obj.attr('signSrc')
                            }else{
                                value= obj.val();
                            }
                        }else{
                            value= obj.val();
                        }

                    }else{
                        value = obj.val() == 0?'':form_item.eq(i).val();
                    }
                }else if(datatype == "radio"){
                    var name = obj.attr('name');
                    if(!radioArr[obj.attr('name')]){
                        radioArr[obj.attr('name')] = true;
                        if($("input[name='"+name+"']:checked").length>0){
                            value= $("input[name='"+name+"']:checked").val();
                        }else{
                            value = "";
                        }
                    }else{
                        continue;
                    }
                }else if(datatype == "imgupload"){

                    $('img[name='+name+']').each(function(i,v){
                        var url = $(v).attr('src');
                        if(url!='/img/icon_uploadimg.png'){
                            value+= (url+',');
                        }
                    })

                }else{
                    value = obj.val();
                }

                if(ismust == 'true' && value == ""){
                    flag = true;
                    layer.msg('请填写'+obj.attr('title'), {icon: 1});
                    break;
                }
                if( value!=null){
                    baseData["key"]=key;
                    baseData["value"]=value;
                    realData.push(baseData);
                }
                if(value != ''){
                    modifydata.push(baseData);
                }
            }
            if(!flag){
                var fdata={
                    flowId:globalData.flowId,
                    formdata:JSON.stringify(realData),
                    runId:globalData.flowRun.runId,
                    runName:globalData.flowRun.runName,
                    beginTime:globalData.flowRun.beginTime,
                    beginUser:globalData.flowRun.beginUser,
                    formLength:globalData.option.formLength,
                    prcsId : globalData.prcsId,
                    flowPrcs : globalData.flowPrcs,
                    modifydata:JSON.stringify(modifydata),
                    fromDataReject:JSON.stringify(globalData.fromDataReject),
                    tableName:globalData.tableName,
                    tabId:globalData.tabId
                };
                $.ajax({
                    type: "post",
                    url: "../../workflow/work/nextwork",
                    dataType: 'JSON',
                    data: fdata,
                    success: function(res){
                        // alert(res.msg);
                        var data ={};
                        if(cb){
                            if(res.flag){
                                data.flag = true;
                            }else{
                                data.flag = false;
                            }
                            data.data = res.obj;
                            cb(data)
                        }
                    }
                });
            }
        },
        buildBody : function(data){
            var _this = (this);
            var target = data;
            var dataList = data.find('.form_item');
            var preObj = '';
            var tableObj = [];
            // console.log(dataList)

            dataList.each(function(i,v) {
                var __this = $(this);
                var dataType = __this.attr('data-type');
                var title = __this.attr('title');
                var name = __this.attr('name');
                var isMust = __this.attr('isMust');
                var isMustText = '';
                object[name] = false;
                arrobject.push(name);
                if(isMust){
                    isMustText = '<span style="color:red;">&nbsp;*</span>';
                }

                var eleTrObj = $('<tr><td class="td1"><div>' + title + isMustText + '</div></td><td class="td2"></td></tr>');
                var e = {};
                var val = "";
                var idnum = 0;
                var checkidnum=0;
                if(__this.attr('secret') == 1){
                    __this.hide();
                    eleTrObj.find('.td2').append(__this).append('*****');
                }else{
                    switch (dataType) {
                        case 'text':
                            // __this.addClass("gapp_input gapp_form");
                            // __this.attr("style",'');
                            val = __this.val();
                            __this.hide();
                            break;
                        case 'markformItem':
                            val = '';
                            eleTrObj.find('.td2').append(__this.parent().prop("outerHTML"));
                            break;
                        case 'textarea':
                            // __this.addClass("gapp_textarea");
                            // __this.attr("style",'');
                            val = __this.val();
                            eleTrObj.find('.td2').append(__this);
                            __this.hide();
                            break;
                        case 'countersignature_item':
                            val = __this.val();
                            eleTrObj.find('.td2').append(__this);
                            __this.hide();
                            break;
                        case 'select':
                            __this.addClass("gapp_select gapp_form");
                            __this.attr("style",'');
                            val = __this.val();
                            __this.hide();
                            break;
                        case 'radio':
                            var bool=true;
                            for(var i=0;i<tableObj.length;i++){
                                if($(tableObj[i]).find('[name="'+__this.attr('name')+'"]').length!=0){
                                    bool=false;
                                }
                            }
                            if(bool) {
                                var radioObj = $('<span style="position: relative;width: 22px;height: 16px;display: inline-block"></span>');
                                var id = __this.attr('name');
                                __this.attr('id', id + '_' + idnum);
                                $(__this).css({
                                    'position': 'absolute',
                                    'top': '0',
                                    'left': '2px'
                                })
                                radioObj.append(__this)
                                var lable = '<label style="left: 0;top: 0;" class="bgweijinyong" for="' + id + '_' + idnum + '"></label>';
                                if(__this.attr('disabled')=='disabled') {
                                    lable = '<label style="left: 0;top: 0;" class="bgyijingyong" for="' + id + '_' + idnum + '"></label>';
                                }
                                radioObj.append(lable);
                                var special = $('<div></div>');
                                special.append(radioObj);
                                special.append('<span  style="height: 36px;line-height: 36px;display: inline-block;padding-left: 5px;' +
                                    'padding-right: 15px;">' + __this.val() + '</span>');
                                eleTrObj.find('.td2').append(special);
                                // eleTrObj.find('.td2')
                                //     .append('<span  style="line-height: 22px;display: inline-block;padding-left: 5px;' +
                                //         'padding-right: 15px;">' + __this.val() + '</span>')
                                idnum++;
                            }else {
                                eleTrObj=$('');
                                for(var i=0;i<tableObj.length;i++){
                                    if($(tableObj[i]).find('[name="'+__this.attr('name')+'"]').length!=0){
                                        var tableObjParent=$(tableObj[i]).find('[name="'+__this.attr('name')+'"]').parent().parent().parent();
                                        var radioObj = $('<span style="position: relative;width: 22px;height: 16px;display: inline-block"></span>');
                                        var id = __this.attr('name');
                                        __this.attr('id', id + '_' + idnum);
                                        $(__this).css({
                                            'position': 'absolute',
                                            'top': '0',
                                            'left': '2px'
                                        })
                                        radioObj.append(__this)
                                        var lable = '<label style="left: 0;top: 0;" class="bgweijinyong" for="' + id + '_' + idnum + '"></label>';
                                        if(__this.attr('disabled')=='disabled') {
                                            lable = '<label style="left: 0;top: 0;" class="bgyijingyong" for="' + id + '_' + idnum + '"></label>';
                                        }
                                        radioObj.append(lable);
                                        var special = $('<div></div>');
                                        special.append(radioObj);
                                        special.append('<span  style="height: 36px;line-height: 36px;display: inline-block;padding-left: 5px;' +
                                            'padding-right: 15px;">' + __this.val() + '</span>')

                                        tableObjParent.append(special);
                                        // tableObjParent.append('<span  style="line-height: 22px;display: inline-block;padding-left: 5px;' +
                                        //         'padding-right: 15px;">' + __this.val() + '</span>')
                                    }
                                }
                                idnum++;
                            }

                            break;
                        // case 'checkbox':
                        //
                        //     break;
                        case 'checkbox':
                            var id = __this.attr('name');
                            __this.attr('id',id+'_'+checkidnum);
                            eleTrObj.find('.td2').append(__this);
                            var lable = '<label class="bgweijinyong" style="border-radius: 0px" for="'+ id+'_'+checkidnum +'"></label>';
                            if(__this.attr('disabled')=='disabled'){
                                lable = '<label class="bgyijingyong" style="border-radius: 0px" for="'+ id+'_'+checkidnum +'"></label>';
                            }
                            eleTrObj.find('.td2').append(lable);
                            checkidnum++;
                            break;
                        case 'macros':
                            // console.log(__this.attr('value'))
                            eleTrObj.find('.td2').html('')
                            if(__this.attr('datafld')=='SYS_USERNAME'&&__this.attr('orgsignImg')==1){
                                if(__this.attr('signSrc')!=""&&__this.attr('signSrc')!=undefined){
                                    var signSpan = '<span><img style="width:100px;height:auto" src="'+__this.attr('signSrc')+'" alt=""></span>'
                                    eleTrObj.find('.td2').append(signSpan);
                                }else{
                                    var signSpan ='';
                                    eleTrObj.find('.td2').append(__this.attr('value'));
                                }

                            }else{
                                eleTrObj.find('.td2').append(__this.attr('value'));
                            }

                            eleTrObj.find('.td2').append(__this);
                            break;
                        case 'calendar':
                            val = __this.val();
                            __this.hide();
                            break;
                        case 'qrcode':

                            eleTrObj.find('.td2').append(__this);
                            break;
                        case 'imgupload':
                            data.find('img[name="'+name+'"]').each(function (i,v) {
                                if($(v).attr("src") != undefined&&$(v).attr("src").indexOf('/img/icon_uploadimg.png') == -1){
                                    $(v).attr('url',$(v).attr('src'));
                                    $(v).attr('src',decodeURI($(v).attr('src')));
                                    $(v).attr('names',$(v).attr('url').split('&ATTACHMENT_NAME=')[1].split('&')[0]);
                                    $(v).attr('onclick','anios1($(this))');
                                    var thisspan = decodeURI($(v).attr("names"));
                                    thisspan = decodeURI(thisspan).replace(/\%2b/g, "+").replace(/\%40/g,"@").replace(/\%23/g,"#").replace(/\%26/g,"&").replace(/\%2F/g,"/").replace(/\%3F/g,"?").replace(/\%ef%bf%a5/g,"￥").replace(/\%24/g,"$").replace(/\%ef%bc%81/g,"！").replace(/\%ef%bc%88/g,"（").replace(/\%ef%bc%89/g,"）").replace(/\%e2%80%a6%e2%80%a6/g,"…");
                                    var attachname = thisspan;
                                    if(thisspan.split('.')[0].length > 8){
                                        var thisspan = thisspan.split('.')[0].substr(0,8)+'…'+thisspan.split('.')[1];
                                    }
                                    $(v).attr('url',$(v).attr('src').split('&ATTACHMENT_NAME=')[0]+'&ATTACHMENT_NAME='+ attachname + '&FILESIZE=' +$(v).attr('src').split('&ATTACHMENT_NAME=')[1].split('&FILESIZE=')[1]);
                                    eleTrObj.find('.td2').css({
                                        'padding-top': '5px',
                                        'padding-bottom': '5px'
                                    }).append('<div class="imgfileBox" style="display:  inline-block;position:  relative;float: left;">'+ v.outerHTML +'<span class="uploadImg">'+ thisspan +'</span></div>');
                                }else{
                                    eleTrObj.find('.td2').append('');
                                }
                            });
                            break;
                        case 'fileupload':
                            data.find('img[name="'+name+'"]').each(function (i,v) {
                                if($(v).attr("src") != undefined&&$(v).attr("src").indexOf('/img/fileupload.png') == -1&&$(v).attr("src").indexOf('/img/icon_uploadimg.png') == -1){
                                    $(v).attr('url',$(v).attr('atturl'));
                                    $(v).attr('names',$(v).attr('url').split('&ATTACHMENT_NAME=')[1].split('&')[0]);
                                    $(v).attr('onclick','anios1($(this))');
                                    if($(v).attr('disabled')!='disabled'){
                                        var thisspan = $(v).attr("names");
                                        /*if(thisspan.split('.')[0].length > 8){
                                            var thisspan = thisspan.split('.')[0].substr(0,8)+'…'+thisspan.split('.')[1];
                                        }*/
                                        eleTrObj.find('.td2').css({
                                            'padding-top': '5px',
                                            'padding-bottom': '5px'
                                        }).append('<div class="imgfileBox" style="display:  inline-block;position:  relative;float: left;">'+ v.outerHTML +'<span class="uploadImg">'+ thisspan +'</span></div>');
                                    }
                                }else{
                                    eleTrObj.find('.td2').append('');
                                }
                            });
                            break;
                        case 'autocode':
                            __this.addClass('gapp_input gapp_form');
                            __this.attr('readonly',"readonly");
                            var targetid =  __this.attr('id')
                            eleTrObj.find('.td2').append(__this.val());
                            break;
                        case 'kgsign':
                            $(__this.find("img").get(0)).attr("style","cursor: pointer; margin: 0 auto;width:100%;height:100%;")
                            eleTrObj.find('.td2').append(__this);
                            break;
                        case 'sign':
                            __this.prev().css("display","")
                            eleTrObj.find('.td2').append(__this.prev());
                            break;
                        case 'macrossign':
                            __this.prev().css("display","")
                            eleTrObj.find('.td2').append(__this.html()||__this.attr('value'));
                            break;
                        case 'calculation':
                            __this.prev().css("display","")
                            eleTrObj.find('.td2').append(__this.val());
                            break;
                        case 'listing':
                            eleTrObj.find('.td2').append('<div class="tableplugin" style="display: none;"></div>')
                            eleTrObj.find('.tableplugin').append(__this);
                            eleTrObj.find('.td2').append('<img class="btn_list" src="/img/workflow/m/list.png" style="float: right; position: relative; width: 25px!important;height: 25px!important;">');
                            break;
                        case 'userselect':
                            val = __this.val();
                            if(val == ''){
                                val = __this.html();//workform.js 在查看详情页面已经将_this变成了div 所以无法取val()
                            }
                            break;
                        case 'deptselect':
                            val = __this.val();
                            if(val == ''){
                                val = __this.html();//workform.js 在查看详情页面已经将_this变成了div 所以无法取val()
                            }
                            break;
                        case 'djsign':
                            eleTrObj.find('.td2').append('<div class="divDJBox"></div>');
                            eleTrObj.find('.td2').append(__this.parent().eq(0));
                            break;
                        case 'writeSign':
                            // eleTrObj.find('.td2').append('<div class="divDJBox"></div>');
                            eleTrObj.find('.td2').append(__this.parent().eq(0));
                            break;
                        default:

                    }
                }
                eleTrObj.find('.td2').append(val);
                //判断控件是二维码控件、单选框控件和复选框控件时 因为控件特性不要将目标隐藏
                if(dataType != 'qrcode'&&dataType != 'radio'&&dataType != 'checkbox'){
                    __this.hide();
                }
                //判断控件是点聚签章控件、单选框控件和复选框控件时 因为控件特性不要将目标重新再添加到页面 造成页面html变化
                if(dataType != 'radio'&&dataType != 'checkbox'&&dataType != 'djsign'){
                    eleTrObj.find('.td2').append(__this);
                }
                tableObj.push(eleTrObj);
                var isHidden = __this.attr("orghidden");
                if(1 == isHidden || 'hidden' == isHidden){
                    $(this).parent().parent().hide();
                }
                globalData.fromDataReject = _this.buildFormData();
            });
            $('#content').append(tableObj);
        },
        buildFormData : function(){
            var arr = {};
            $("#content").find('.form_item').each(function(i,v){
                var _this = $(this);
                arr[_this.attr('title')] = _this.attr('name');
            });
            return arr;
        },
        tool:{
            ajaxHtml:function (url,data,cb) {
                var that = this;
                $.ajax({
                    type: "get",
                    url: url,
                    async:false,
                    dataType: 'JSON',
                    data:  data,
                    success: function (res) {
                        if(cb){
                            cb(res);
                        }
                    },
                    error:function(e){
                    }
                });
            }
        }
    }
    workformh5.init(function(){
        turn = function(){
            workformh5.turnH5Btn();
        }
    });
});